-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[HLSL] Add support for fixed-size global resource arrays #152209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adds support for fixed-size resource arrays declared at the global scope. When a global resource array is indexed to access an individual resource, codegen will translate the `ArraySubscriptExpr` into a constructor call for the specific resource record type and binding. Closes llvm#145424
Making this a draft for now because it only supports @s-perron - is your change ready to get merged? |
…urce-array-subscript-one
I'll see what I can do. I'm on vacation right now. I need to make the change you suggested |
…urce arrays (and cbuffers)
If that's the only thing blocking the merge, feel free to go ahead and merge it without my suggested change. I can do the update on my side. I think I need to move that function higher in the file anyway. |
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/include/clang/AST/Type.h clang/include/clang/Sema/SemaHLSL.h clang/lib/AST/Type.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Sema/SemaHLSL.cpp View the diff from clang-format here.diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 8a362cc55..915e967c3 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -857,7 +857,8 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
}
// find binding info for the resource array
- // (for implicit binding an HLSLResourceBindingAttr should have been added by SemaHLSL)
+ // (for implicit binding an HLSLResourceBindingAttr should have been added by
+ // SemaHLSL)
QualType ResourceTy = ArraySubsExpr->getType();
HLSLVkBindingAttr *VkBinding = ArrayDecl->getAttr<HLSLVkBindingAttr>();
HLSLResourceBindingAttr *RBA = ArrayDecl->getAttr<HLSLResourceBindingAttr>();
@@ -865,8 +866,9 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
// lookup the resource class constructor based on the resource type and
// binding
- CXXConstructorDecl *CD = findResourceConstructorDecl(
- ArrayDecl->getASTContext(), ResourceTy, VkBinding || RBA->hasRegisterSlot());
+ CXXConstructorDecl *CD =
+ findResourceConstructorDecl(ArrayDecl->getASTContext(), ResourceTy,
+ VkBinding || RBA->hasRegisterSlot());
// create a temporary variable for the resource class instance (we need to
// return an LValue)
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 5bfb8b933..baf30f6a9 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -3750,9 +3750,9 @@ void SemaHLSL::createResourceRecordCtorArgs(const Type *ResourceTy,
uint32_t OrderID = (RBA && RBA->hasImplicitBindingOrderID())
? RBA->getImplicitBindingOrderID()
: getNextImplicitBindingOrderID();
- IntegerLiteral *OrderId = IntegerLiteral::Create(
- AST, llvm::APInt(UIntTySize, OrderID), AST.UnsignedIntTy,
- SourceLocation());
+ IntegerLiteral *OrderId =
+ IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, OrderID),
+ AST.UnsignedIntTy, SourceLocation());
Args.append({Space, RangeSize, Index, OrderId, Name});
}
}
|
I am going to split the PR into 2 to make it easier to review. |
Adds support for fixed-size resource arrays declared at the global scope.
When a global resource array is indexed to access an individual resource, codegen will translate the
ArraySubscriptExpr
into a constructor call for the specific resource record type and binding.Closes #145424